import { defineStore } from 'pinia';
import { ref } from 'vue';
import { getLocalTimeZone, today } from '@internationalized/date';

interface DateRange {
  start: string;
  end: string;
}

export const useCalendarStore = defineStore('calendar', () => {
  // 默认日期范围：今天到7天后
  const start = today(getLocalTimeZone()).toString();
  const end = today(getLocalTimeZone())
    .add({ days: 7 })
    .toString();

  // 日期范围状态
  const dateRange = ref({
    start,
    end,
  });

  // 设置日期范围
  const setDateRange = (range: DateRange) => {
    dateRange.value = range;
  };

  // 获取开始日期
  const getStartDate = () => dateRange.value.start;

  // 获取结束日期
  const getEndDate = () => dateRange.value.end;

  return {
    dateRange,
    setDateRange,
    getStartDate,
    getEndDate,
  };
});
